package com.wicket.okrbff.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrapp.integration.dto.*;
import com.wicket.okrbff.biz.service.CustomExecutionCycleService;
import com.wicket.okrbff.biz.service.dto.req.*;
import com.wicket.okrbff.biz.service.dto.res.*;
import com.wicket.okrbff.common.ro.OkrResult;
import com.wicket.okrbff.common.ro.OkrResult;
import com.wicket.okrbff.common.util.CommonFunctionHelper;
import com.wicket.okrbff.common.util.RedisUtil;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrapp.integration.FwAppCustomExecutionCycleClient;
import com.wicket.okrbff.common.exception.Assert;
import com.wicket.okrbff.biz.service.dto.common.BffTargetContPlanWorkTimeDto;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollectionUtil;
import com.wicket.okrapp.integration.FwAppTargetCycleClient;
import com.wicket.okrapp.integration.FwAppExecuteProgressClient;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class CustomExecutionCycleServiceImpl
  implements CustomExecutionCycleService {

  @Resource
  private RedisUtil redisUtil;
@Resource
  FwAppCustomExecutionCycleClient fwAppCustomExecutionCycleClient;
@Resource
  FwAppTargetCycleClient fwAppTargetCycleClient;
@Resource
  FwAppExecuteProgressClient fwAppExecuteProgressClient;
/**
   * B3获取上级目标内容实际工作起止时间(管理)[6880]
   * gen by moon at 5/25/2023, 12:25:22 AM
   */
    @Trace(operationName = "B3获取上级目标内容实际工作起止时间(管理)")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffObtainParentTargetContActualWorkTimeRespDto obtainParentTargetContActualWorkTime(BffObtainParentTargetContActualWorkTimeReqDto reqDto){
      
       
       ObtainParentTargetContActualWorkTimeRespDto obtainParentTargetContActualWorkTimeRespDto_1 =null;
//步骤0: D3获取上级目标内容实际工作起止时间 - obtainParentTargetContActualWorkTime
     ObtainParentTargetContActualWorkTimeRespDto obtainParentTargetContActualWorkTimeRespDto = null;
    ObtainParentTargetContActualWorkTimeReqDto obtainParentTargetContActualWorkTimeReqDto=new ObtainParentTargetContActualWorkTimeReqDto();
  if(reqDto!=null){
      obtainParentTargetContActualWorkTimeReqDto.setEvaObjTargetCycleId(reqDto.getEvaObjTargetCycleId());//SimpleFieldAssign//sourceId:965090_1
obtainParentTargetContActualWorkTimeReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:965089_1
    }
  
    /*D3获取上级目标内容实际工作起止时间[6877]   */
    Assert.isNull(obtainParentTargetContActualWorkTimeReqDto.getEvaObjTargetCycleId(),"B3获取上级目标内容实际工作起止时间(管理)-D3获取上级目标内容实际工作起止时间-被评对象目标周期ID不能为空",false);
    Assert.isNull(obtainParentTargetContActualWorkTimeReqDto.getEvaluationTemplateId(),"B3获取上级目标内容实际工作起止时间(管理)-D3获取上级目标内容实际工作起止时间-冗余评价模板ID不能为空",false);
      obtainParentTargetContActualWorkTimeRespDto = fwAppCustomExecutionCycleClient.obtainParentTargetContActualWorkTime(obtainParentTargetContActualWorkTimeReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      obtainParentTargetContActualWorkTimeRespDto_1 = obtainParentTargetContActualWorkTimeRespDto;
    
BffObtainParentTargetContActualWorkTimeRespDto retData = new BffObtainParentTargetContActualWorkTimeRespDto();
  if(obtainParentTargetContActualWorkTimeRespDto_1!=null){
      retData.setTargetCyclePlanSetId(obtainParentTargetContActualWorkTimeRespDto_1.getTargetCyclePlanSetId());//SimpleFieldAssign//sourceId:965099_1
retData.setTargetActualStartTime(obtainParentTargetContActualWorkTimeRespDto_1.getTargetActualStartTime());//SimpleFieldAssign//sourceId:965100_1
retData.setTargetActualEndtTime(obtainParentTargetContActualWorkTimeRespDto_1.getTargetActualEndtTime());//SimpleFieldAssign//sourceId:965101_1
    }
  

  
  
return retData;
  }
/**
   * B3获取目标内容计划工作时间(管理)[6871]
   * gen by moon at 4/28/2024, 2:42:03 PM
   */
    @Trace(operationName = "B3获取目标内容计划工作时间(管理)")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffObtainTargetContPlanWorkTimeRespDto obtainTargetContPlanWorkTime(BffObtainTargetContPlanWorkTimeReqDto reqDto){
      
       
       ObtainTargetContPlanWorkTimeRespDto obtainTargetContPlanWorkTimeRespDto_1 =null;
BatchQueryEvaObjTargetCycleRespDto batchQueryEvaObjTargetCycleRespDto_1 =null;
//步骤0: D3获取目标内容计划工作时间 - obtainTargetContPlanWorkTime
     ObtainTargetContPlanWorkTimeRespDto obtainTargetContPlanWorkTimeRespDto = null;
    ObtainTargetContPlanWorkTimeReqDto obtainTargetContPlanWorkTimeReqDto=new ObtainTargetContPlanWorkTimeReqDto();
  if(reqDto!=null){
      obtainTargetContPlanWorkTimeReqDto.setEntityId(reqDto.getEntityId());//SimpleFieldAssign//sourceId:962753_1
obtainTargetContPlanWorkTimeReqDto.setTableTypeCode(reqDto.getTableTypeCode());//SimpleFieldAssign//sourceId:962752_1
obtainTargetContPlanWorkTimeReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:962751_1
    }
  
    /*D3获取目标内容计划工作时间[6867]   */
    Assert.isNull(obtainTargetContPlanWorkTimeReqDto.getEntityId(),"B3获取目标内容计划工作时间(管理)-D3获取目标内容计划工作时间-内容表主键ID不能为空",false);
Assert.isNull(obtainTargetContPlanWorkTimeReqDto.getTableTypeCode(),"B3获取目标内容计划工作时间(管理)-D3获取目标内容计划工作时间-内容表类型编码不能为空",false);
Assert.isNull(obtainTargetContPlanWorkTimeReqDto.getEvaluationTemplateId(),"B3获取目标内容计划工作时间(管理)-D3获取目标内容计划工作时间-冗余评价模板ID不能为空",false);
      obtainTargetContPlanWorkTimeRespDto = fwAppCustomExecutionCycleClient.obtainTargetContPlanWorkTime(obtainTargetContPlanWorkTimeReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      obtainTargetContPlanWorkTimeRespDto_1 = obtainTargetContPlanWorkTimeRespDto;

//步骤1: D3-3批量查询被评对象目标周期 - batchQueryEvaObjTargetCycle
      BatchQueryEvaObjTargetCycleRespDto batchQueryEvaObjTargetCycleRespDto = null;
    if(obtainTargetContPlanWorkTimeRespDto !=null){
          BatchQueryEvaObjTargetCycleReqDto batchQueryEvaObjTargetCycleReqDto=new BatchQueryEvaObjTargetCycleReqDto();
  batchQueryEvaObjTargetCycleReqDto.setIsArchive("FALSE");//sourceId:980946_1
if(obtainTargetContPlanWorkTimeRespDto!= null&&  obtainTargetContPlanWorkTimeRespDto.getTargetContPlanWorkTimeList() !=null&& !CollectionUtil.isEmpty(obtainTargetContPlanWorkTimeRespDto.getTargetContPlanWorkTimeList())){
      batchQueryEvaObjTargetCycleReqDto.setEvaObjTargetCycleList(obtainTargetContPlanWorkTimeRespDto.getTargetContPlanWorkTimeList().stream().map(item->item.getEvaObjTargetCycleId())
        .collect(Collectors.toList()));/*list-to-strings*///sourceId:980944_1
    }
if(reqDto!=null){
      batchQueryEvaObjTargetCycleReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:980945_1
    }

    /*D3-3批量查询被评对象目标周期[5445]   */
    Assert.isNull(batchQueryEvaObjTargetCycleReqDto.getEvaluationTemplateId(),"B3获取目标内容计划工作时间(管理)-D3-3批量查询被评对象目标周期-冗余评价模板ID不能为空",false);
Assert.isNull(batchQueryEvaObjTargetCycleReqDto.getIsArchive(),"B3获取目标内容计划工作时间(管理)-D3-3批量查询被评对象目标周期-是否存档不能为空",false);
      batchQueryEvaObjTargetCycleRespDto = fwAppTargetCycleClient.batchQueryEvaObjTargetCycle(batchQueryEvaObjTargetCycleReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


      batchQueryEvaObjTargetCycleRespDto_1 = batchQueryEvaObjTargetCycleRespDto;
           }
BffObtainTargetContPlanWorkTimeRespDto retData = new BffObtainTargetContPlanWorkTimeRespDto();
  //数据集融合  MoreListToOneSource
        if(obtainTargetContPlanWorkTimeRespDto_1!= null && !CollectionUtil.isEmpty(obtainTargetContPlanWorkTimeRespDto_1.getTargetContPlanWorkTimeList()) ){
          for (TargetContPlanWorkTimeDto targetContPlanWorkTimeDto : obtainTargetContPlanWorkTimeRespDto_1.getTargetContPlanWorkTimeList()) {
              BffTargetContPlanWorkTimeDto retElm = new BffTargetContPlanWorkTimeDto();
  if(obtainTargetContPlanWorkTimeRespDto_1!=null){
      retElm.setTargetCyclePlanSetId(targetContPlanWorkTimeDto.getTargetCyclePlanSetId());//SimpleFieldAssign//sourceId:354810_2
retElm.setEvaObjTargetCycleId(targetContPlanWorkTimeDto.getEvaObjTargetCycleId());//SimpleFieldAssign//sourceId:354811_2
retElm.setTargetActualStartTime(targetContPlanWorkTimeDto.getTargetActualStartTime());//SimpleFieldAssign//sourceId:354812_2
retElm.setTargetActualEndtTime(targetContPlanWorkTimeDto.getTargetActualEndtTime());//SimpleFieldAssign//sourceId:354813_2
    }
              retData.getTargetContPlanWorkTimeList().add(retElm);
               if(batchQueryEvaObjTargetCycleRespDto_1!= null){
          for (EvaObjTargetCycleDto evaObjTargetCycleDto : batchQueryEvaObjTargetCycleRespDto_1.getEvaObjTargetCycleList()) {
                if (evaObjTargetCycleDto.getEvaObjTargetCycleId().equals(targetContPlanWorkTimeDto.getEvaObjTargetCycleId())) {
                 if(batchQueryEvaObjTargetCycleRespDto_1!=null){
      retElm.setCycleStandardName(evaObjTargetCycleDto.getCycleStandardName());//SimpleFieldAssign//sourceId:354814_2
retElm.setCycleStartTime(evaObjTargetCycleDto.getCycleStartTime());//SimpleFieldAssign//sourceId:354815_2
retElm.setCycleEndTime(evaObjTargetCycleDto.getCycleEndTime());//SimpleFieldAssign//sourceId:354816_2
    }
                }
            }
          }

          }
        }//sourceId:962761_1
if(obtainTargetContPlanWorkTimeRespDto_1!=null){
      retData.setTargetCycleParentCycleId(obtainTargetContPlanWorkTimeRespDto_1.getTargetCycleParentCycleId());//SimpleFieldAssign//sourceId:1761563_1
retData.setTargetCycleMidCycleId(obtainTargetContPlanWorkTimeRespDto_1.getTargetCycleMidCycleId());//SimpleFieldAssign//sourceId:1761564_1
retData.setIsOpenCustomReport(obtainTargetContPlanWorkTimeRespDto_1.getIsOpenCustomReport());//SimpleFieldAssign//sourceId:981766_1
retData.setCutCycleReportTimeTypeCode(obtainTargetContPlanWorkTimeRespDto_1.getCutCycleReportTimeTypeCode());//SimpleFieldAssign//sourceId:1760638_1
retData.setTempIsOpenCustomReport(obtainTargetContPlanWorkTimeRespDto_1.getTempIsOpenCustomReport());//SimpleFieldAssign//sourceId:1221579_1
    }
  

  
  
return retData;
  }
/**
   * B3设置目标内容实际工作起止时间等(管理)[6878]
   * gen by moon at 4/30/2024, 2:16:33 AM
   */
    @Trace(operationName = "B3设置目标内容实际工作起止时间等(管理)")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffSetTargetContActualWorkTimeEtcRespDto setTargetContActualWorkTimeEtc(BffSetTargetContActualWorkTimeEtcReqDto reqDto){
      
       
       ImplementExecuteProgressOperationJudgeComRespDto implementExecuteProgressOperationJudgeComRespDto_1 =null;
//virtualUsage D3执行进度运行判断(公共)  47547
      ImplementExecuteProgressOperationJudgeComRespDto implementExecuteProgressOperationJudgeComRespDto = null;
    ImplementExecuteProgressOperationJudgeComReqDto implementExecuteProgressOperationJudgeComReqDto=new ImplementExecuteProgressOperationJudgeComReqDto();
  implementExecuteProgressOperationJudgeComReqDto.setUseTypeCode("USE_CUSTOM_EXECUTE_CYCLE");//CUSTOM_CONVENTION//sourceId:1086198_1_47547
if(reqDto!=null){
      implementExecuteProgressOperationJudgeComReqDto.setObjectId(reqDto.getTargetCycleParentCycleId());//SimpleFieldAssign//sourceId:1086197_1_47547
implementExecuteProgressOperationJudgeComReqDto.setThemeContentId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:1086199_1_47547
    }

    /*D3执行进度运行判断(公共)[7243]   */
    Assert.isNull(implementExecuteProgressOperationJudgeComReqDto.getObjectId(),"B3设置目标内容实际工作起止时间等(管理)-D3执行进度运行判断(公共)-归属对象内容ID不能为空",false);
Assert.isNull(implementExecuteProgressOperationJudgeComReqDto.getUseTypeCode(),"B3设置目标内容实际工作起止时间等(管理)-D3执行进度运行判断(公共)-用途类型编码不能为空",false);
Assert.isNull(implementExecuteProgressOperationJudgeComReqDto.getThemeContentId(),"B3设置目标内容实际工作起止时间等(管理)-D3执行进度运行判断(公共)-主题内容ID不能为空",false);
      implementExecuteProgressOperationJudgeComRespDto = fwAppExecuteProgressClient.implementExecuteProgressOperationJudgeCom(implementExecuteProgressOperationJudgeComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


      implementExecuteProgressOperationJudgeComRespDto_1 = implementExecuteProgressOperationJudgeComRespDto;
if((implementExecuteProgressOperationJudgeComRespDto!= null&& implementExecuteProgressOperationJudgeComRespDto.getCustomField() == null )) {
        //if(D3执行进度运行判断(公共).操作过于频繁，请稍后再试文案故事 值等于空 )  47548

     SetTargetContActualWorkTimeEtcRespDto setTargetContActualWorkTimeEtcRespDto = null;
    SetTargetContActualWorkTimeEtcReqDto setTargetContActualWorkTimeEtcReqDto=new SetTargetContActualWorkTimeEtcReqDto();
  setTargetContActualWorkTimeEtcReqDto.setUseTypeCode("USE_CUSTOM_EXECUTE_CYCLE");//CUSTOM_CONVENTION//sourceId:1081810_1_47549
  if(reqDto!= null&&  reqDto.getDutyCycleTargetList() !=null&& !CollectionUtil.isEmpty(reqDto.getDutyCycleTargetList())){
      setTargetContActualWorkTimeEtcReqDto.setTargetContPlanWorkTimeList(reqDto.getDutyCycleTargetList().stream().map(item -> BeanUtil.toBean(item, TargetContPlanWorkTimeDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:964215_1_47549
    }
if(reqDto!=null){
      setTargetContActualWorkTimeEtcReqDto.setTargetCycleParentCycleId(reqDto.getTargetCycleParentCycleId());//SimpleFieldAssign//sourceId:964211_1_47549
setTargetContActualWorkTimeEtcReqDto.setTargetCycleMidCycleId(reqDto.getTargetCycleMidCycleId());//SimpleFieldAssign//sourceId:964212_1_47549
setTargetContActualWorkTimeEtcReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:964214_1_47549
setTargetContActualWorkTimeEtcReqDto.setIsOpenCustomExecuteCycle(reqDto.getIsOpenCustomExecuteCycle());//SimpleFieldAssign//sourceId:1762152_1_47549
    }
  
    /*D3设置目标内容实际工作起止时间等[6876]   */
    Assert.isNull(setTargetContActualWorkTimeEtcReqDto.getTargetCycleParentCycleId(),"B3设置目标内容实际工作起止时间等(管理)-D3设置目标内容实际工作起止时间等-目标周期父周期ID不能为空",false);
Assert.isNull(setTargetContActualWorkTimeEtcReqDto.getEvaluationTemplateId(),"B3设置目标内容实际工作起止时间等(管理)-D3设置目标内容实际工作起止时间等-冗余评价模板ID不能为空",false);
Assert.isNull(setTargetContActualWorkTimeEtcReqDto.getUseTypeCode(),"B3设置目标内容实际工作起止时间等(管理)-D3设置目标内容实际工作起止时间等-用途类型编码不能为空",false);
Assert.isNull(setTargetContActualWorkTimeEtcReqDto.getIsOpenCustomExecuteCycle(),"B3设置目标内容实际工作起止时间等(管理)-D3设置目标内容实际工作起止时间等-是否开启自定义执行周期不能为空",false);
      setTargetContActualWorkTimeEtcRespDto = fwAppCustomExecutionCycleClient.setTargetContActualWorkTimeEtc(setTargetContActualWorkTimeEtcReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
      }
BffSetTargetContActualWorkTimeEtcRespDto retData = new BffSetTargetContActualWorkTimeEtcRespDto();
  if(implementExecuteProgressOperationJudgeComRespDto_1!=null){
      retData.setCustomField(implementExecuteProgressOperationJudgeComRespDto_1.getCustomField());//SimpleFieldAssign//sourceId:1086201_1
    }
  

  
  
return retData;
  }
  //
}
